Skip to content

Conversation

@jurahul
Copy link
Contributor

@jurahul jurahul commented May 16, 2025

Initialize vectors using constructor instead of llvm::append_range when possible.

@jurahul jurahul force-pushed the table_use_sv_range_ctor branch 2 times, most recently from f36c638 to 55f4288 Compare May 17, 2025 14:20
Initialize vectors using constructors instead of llvm::append_range
when possible.
@jurahul jurahul force-pushed the table_use_sv_range_ctor branch from 55f4288 to dc9bceb Compare May 19, 2025 15:51
@jurahul jurahul marked this pull request as ready for review May 19, 2025 17:24
@jurahul jurahul requested a review from kazutakahirata May 19, 2025 17:24
@llvmbot
Copy link
Member

llvmbot commented May 19, 2025

@llvm/pr-subscribers-tablegen

Author: Rahul Joshi (jurahul)

Changes

Initialize vectors using constructors instead of llvm::append_range when possible.


Full diff: https://github.com/llvm/llvm-project/pull/140284.diff

2 Files Affected:

  • (modified) llvm/lib/TableGen/Record.cpp (+7-11)
  • (modified) llvm/utils/TableGen/Common/CodeGenRegisters.cpp (+1-2)
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 97e185bbd1267..59884c78565a6 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -334,11 +334,10 @@ static const RecordRecTy *resolveRecordTypes(const RecordRecTy *T1,
   while (!Stack.empty()) {
     const Record *R = Stack.pop_back_val();
 
-    if (T2->isSubClassOf(R)) {
+    if (T2->isSubClassOf(R))
       CommonSuperClasses.push_back(R);
-    } else {
-      append_range(Stack, make_first_range(R->getDirectSuperClasses()));
-    }
+    else
+      llvm::append_range(Stack, make_first_range(R->getDirectSuperClasses()));
   }
 
   return RecordRecTy::get(T1->getRecordKeeper(), CommonSuperClasses);
@@ -2733,11 +2732,8 @@ const DagInit *DagInit::get(const Init *V, const StringInit *VN,
 const DagInit *DagInit::get(
     const Init *V, const StringInit *VN,
     ArrayRef<std::pair<const Init *, const StringInit *>> ArgAndNames) {
-  SmallVector<const Init *, 8> Args;
-  SmallVector<const StringInit *, 8> Names;
-
-  llvm::append_range(Args, make_first_range(ArgAndNames));
-  llvm::append_range(Names, make_second_range(ArgAndNames));
+  SmallVector<const Init *, 8> Args(make_first_range(ArgAndNames));
+  SmallVector<const StringInit *, 8> Names(make_second_range(ArgAndNames));
   return DagInit::get(V, VN, Args, Names);
 }
 
@@ -2901,8 +2897,8 @@ void Record::checkName() {
 }
 
 const RecordRecTy *Record::getType() const {
-  SmallVector<const Record *, 4> DirectSCs;
-  append_range(DirectSCs, make_first_range(getDirectSuperClasses()));
+  SmallVector<const Record *> DirectSCs(
+      make_first_range(getDirectSuperClasses()));
   return RecordRecTy::get(TrackedRecords, DirectSCs);
 }
 
diff --git a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
index 3b7604a05fa88..a833e488c5e33 100644
--- a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
@@ -650,8 +650,7 @@ struct TupleExpander : SetTheory::Expander {
 
       // Take the cost list of the first register in the tuple.
       const ListInit *CostList = Proto->getValueAsListInit("CostPerUse");
-      SmallVector<const Init *, 2> CostPerUse;
-      llvm::append_range(CostPerUse, *CostList);
+      SmallVector<const Init *, 2> CostPerUse(CostList->getValues());
 
       const StringInit *AsmName = StringInit::get(RK, "");
       if (!RegNames.empty()) {

Copy link
Contributor

@kazutakahirata kazutakahirata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@jurahul jurahul merged commit 0f38543 into llvm:main May 19, 2025
14 checks passed
@jurahul jurahul deleted the table_use_sv_range_ctor branch May 19, 2025 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants